#include "imagegetimageresponse.h"

// Qt includes
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QPixmap>

namespace Network {

GetImageResponse::GetImageResponse(QObject *parent) :
    Network::Response(parent),
    m_originalPixmap(NULL)
{
    m_baseUrl = QUrl("http://avatar.me.zdn.vn");
    m_redirected = false;
}

GetImageResponse::~GetImageResponse()
{

}

bool GetImageResponse::isRedirected() const
{
    return m_redirected;
}

void GetImageResponse::parse(QNetworkReply &reply)
{
    QNetworkReply::NetworkError error = reply.error();
    if (error != QNetworkReply::NoError) {
        setError(Network, reply.errorString());
        return;
    }
    QByteArray data = reply.readAll();
    parse(data);
}

Network::Response::Type GetImageResponse::type() const
{
    return Network::Response::GetImage;
}

void GetImageResponse::parse(const QByteArray &data)
{
    m_originalPixmap = new QPixmap();
    m_originalPixmap->loadFromData(data);
}

QPixmap *GetImageResponse::pixmap() const
{
    return m_originalPixmap;
}

} // namespace Network
